<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" th:replace="~{fragments/layout :: layout(~{::title}, ~{::section})}">

<head>
    <title>评论详情 - 图书馆管理系统</title>
</head>

<body>
    <section>
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2>评论详情</h2>
            <a href="/comment/list" class="btn btn-secondary">
                <i class="fas fa-arrow-left"></i> 返回列表
            </a>
        </div>

        <div class="card">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>评论ID</label>
                            <p class="form-control-static" th:text="${comment.id}"></p>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>评论用户</label>
                            <p class="form-control-static" th:text="${comment.userName}"></p>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>图书名称</label>
                            <p class="form-control-static" th:text="${comment.bookName}"></p>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>评分</label>
                            <p class="form-control-static">
                                <span th:each="i : ${#numbers.sequence(1, comment.rating)}">
                                    <i class="fas fa-star text-warning"></i>
                                </span>
                                <span th:each="i : ${#numbers.sequence(comment.rating + 1, 5)}">
                                    <i class="far fa-star text-warning"></i>
                                </span>
                            </p>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label>评论内容</label>
                            <p class="form-control-static" th:text="${comment.content}"></p>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>状态</label>
                            <p class="form-control-static">
                                <span th:if="${comment.status == 1}" class="badge badge-success">显示</span>
                                <span th:if="${comment.status == 0}" class="badge badge-secondary">隐藏</span>
                            </p>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>评论时间</label>
                            <p class="form-control-static" th:text="${#temporals.format(comment.createTime, 'yyyy-MM-dd HH:mm:ss')}"></p>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <a th:href="@{/comment/edit/{id}(id=${comment.id})}" class="btn btn-primary">
                                <i class="fas fa-edit"></i> 编辑
                            </a>
                            <button type="button" class="btn btn-danger" onclick="deleteComment()">
                                <i class="fas fa-trash"></i> 删除
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script>
            function deleteComment() {
                if (confirm('确定要删除这条评论吗？')) {
                    $.ajax({
                        url: '/comment/api/delete/' + [[${comment.id}]],
                        type: 'DELETE',
                        success: function (res) {
                            if (res.code === 200) {
                                alert('删除成功！');
                                window.location.href = '/comment/list';
                            } else {
                                alert('删除失败：' + res.message);
                            }
                        },
                        error: function () {
                            alert('服务器错误，请稍后再试！');
                        }
                    });
                }
            }
        </script>
    </section>
</body>

</html> 